package com.resp;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Servlet11")
public class Servlet11 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行了servlet11....");

        //获取ServletContext对象
        ServletContext servletContext = req.getServletContext();

        //获取资源的真实路径
        //String realPath = servletContext.getRealPath("");//D:\Ruanjian\apache-tomcat-8.5.68\webapps\ROOT\
        String realPath = servletContext.getRealPath("test05.html");//D:\Ruanjian\apache-tomcat-8.5.68\webapps\ROOT\test05.html
        System.out.println(realPath);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
